//
//  HELNavigationContrller.m
//  sanda
//
//  Created by wsj2015 on 16/7/12.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "HELNavigationContrller.h"
#import "HELPersonVC.h"
#import "UIImage+SQExtension.h"
#import "UIViewController+BackButtonHandler.h"
@interface HELNavigationContrller ()

@end

@implementation HELNavigationContrller






- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   
    [self.navigationBar setBackgroundImage:[UIImage imageWithColor:kMainColor] forBarMetrics:UIBarMetricsDefault];
    [self.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    //    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationBar.shadowImage = [[UIImage alloc] init];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    self.navigationBar.translucent = NO;
   
    
}



//- (void)resetNav{
//
////    [self.navigationBar setBarTintColor:[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0]];
//    [self.navigationBar setBackgroundImage:[UIImage imageWithColor:kMainColor] forBarMetrics:UIBarMetricsDefault];
//    [self.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
////    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
//    self.navigationBar.shadowImage = [[UIImage alloc] init];
//    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
//   self.navigationBar.translucent = NO;
//  
//}

//- (void)firstNav{
//    [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bg"] forBarMetrics:UIBarMetricsDefault];
////    self.navigationBar.barTintColor =[UIColor colorWithRed:20/255 green:30/255 blue:100/255 alpha:.4];
//    self.navigationBar.shadowImage = [UIImage new];
//    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
//    [self.navigationBar setTintColor:[UIColor whiteColor]];
//    self.navigationBar.translucent = YES;
////    se
////     [[UINavigationBar appearance] setTranslucent:YES];
//   
//}


- (instancetype)init
{
    self = [super init];
    if (self) {
       
    }
    return self;
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    //    NSLog(@"%@",self.viewControllers);
    if (self.viewControllers.count != 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    [super pushViewController:viewController animated:animated];
}



- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem*)item {
    
    if([self.viewControllers count] < [navigationBar.items count]) {
        return YES;
    }
    
    BOOL shouldPop = YES;
    UIViewController* vc = [self topViewController];
    if([vc respondsToSelector:@selector(navigationShouldPopOnBackButton)]) {
        shouldPop = [vc navigationShouldPopOnBackButton];
    }
    
    if(shouldPop) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self popViewControllerAnimated:YES];
        });
    } else {
        // Workaround for iOS7.1. Thanks to @boliva - http://stackoverflow.com/posts/comments /34452906
        for(UIView *subview in [navigationBar subviews]) {
            if(subview.alpha < 1.) {
                [UIView animateWithDuration:.25 animations:^{
                    subview.alpha = 1.;
                }];
            }
        }
    }
    
    return NO;
}

//导航控制器内的所有vc 只支持竖屏

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    if (isIOS8) {
        return UIInterfaceOrientationMaskAll;
    }
    return UIInterfaceOrientationMaskPortrait ;
}

@end
